package com.smarthome.common.exception;

import com.smarthome.domain.enums.ResponseCode;
import com.smarthome.domain.enums.SmsExceptionEnum;

public class ExceptionUtils {

    public static void throwAppException(Exception e) throws DataErrorException {
        throw new AppException(e);
    }

    /**
     * expect=true时抛出DataErrorException异常
     * @param expect
     * @param msg
     */
    public static void throwDataError(boolean expect, String msg) throws DataErrorException {
        if (expect) {
            throw new DataErrorException(msg);
        }
    }

    /**
     * expect=true时抛出NotAuthException异常
     * @param expect
     * @param msg
     */
    public static void throwNotAuth(boolean expect, String msg) throws NotAuthException {
        if (expect) {
            throw new NotAuthException(msg);
        }
    }

    /**
     * expect=true时抛出ParamErrorException异常
     * @param expect
     * @param msg
     */
    public static void throwParamError(boolean expect, ResponseCode responseCode, Object... args) throws ParamException {
        if (expect) {
            throw new ParamException(responseCode, args);
        }
    }

    /**
     * expect=true时抛出ParamErrorException异常
     * @param expect
     * @param msg
     */
    public static void throwParamError(ResponseCode responseCode, Object... args) throws ParamException {
        throw new ParamException(responseCode, args);
    }

    /**
     * expect=true时抛出RpcConnectException异常
     * @param expect
     * @param msg
     */
    public static void throwRpcConnect(boolean expect, String msg) throws ParamException {
        if (expect) {
            throw new RpcConnectException(msg);
        }
    }

    /**
     * 抛出RpcConnectException异常
     * @param e
     */
    public static void throwSms(Exception e) throws SmsException {
        throw new SmsException(e);
    }
    
    /**
     * 抛出RpcConnectException异常
     * @param e
     */
    public static void throwSms(SmsExceptionEnum exceptionEnum) throws SmsException {
    	throw new SmsException(exceptionEnum);
    }
    /**
     * 抛出RpcConnectException异常
     * @param e
     */
    public static void throwSms(Exception e,SmsExceptionEnum exceptionEnum) throws SmsException {
    	throw new SmsException(e,exceptionEnum);
    }

    /**
     * 抛出SmsException异常
     * @param msg
     * @param e
     */
    public static void throwSms(String msg, Exception e) throws SmsException {
        throw new SmsException(msg, e);
    }
    
    
    /**
     * 抛出SmsException异常
     * @param e
     */
    public static void throwRpcConnect(Exception e) throws RpcConnectException {
    	throw new RpcConnectException(e);
    }
    
    /**
     * 抛出RpcConnectException异常
     * @param msg
     * @param e
     */
    public static void throwRpcConnect(String msg, Exception e) throws RpcConnectException {
    	throw new RpcConnectException(msg, e);
    }

    /**
     * 抛出BaseException异常
     * @param exceptionType
     * @param args
     * @throws BaseException
     */
    public static void throwBaseException(ResponseCode responseCode, Object... args) throws BaseException {
        throw new BaseException(responseCode, String.format(responseCode.getReferCode(), args));
    }

    public static void throwRuleEngineException(boolean expect, String msg) throws RuleEngineException {
        if (expect) {
            throw new RuleEngineException(msg);
        }
    }

    public static void throwRuleEngineException(Exception e) throws RuleEngineException {
        throw new RuleEngineException(e);
    }

    public static void throwRuleEngineException(String msg, Exception e) throws RuleEngineException {
        throw new RuleEngineException(msg, e);
    }

    /**
     * 抛出BaseException异常
     * @param exceptionType
     * @param args
     * @throws BaseException
     */
    public static void throwCommonException(ResponseCode responseCode, Object... args) throws BaseException {
        throwBaseException(responseCode, args);
    }
}
